<!--
 * @Description: 系统账单管理
 * @Author: yang
 * @Date: 2021-06-24 17:20:10
 * @LastEditors: Morgan
 * @LastEditTime: 2021-07-02 17:12:28
-->
<template>
  <!-- 系统账单管理 -->
  <div search>
    <!-- 查询 列-->
    <!-- 日期 -->
    <div class="search">
      <!-- form表单 -->
      <el-form :inline="true" :model="searchForm" class="demo-form-inline">
        <el-date-picker
          v-model="searchForm.Time"
          value-format="timestamp"
          type="datetimerange"
          :picker-options="pickerOptions"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          align="right"
        />
        <el-form-item>
          <el-select v-model="searchForm.type" placeholder="请选择类型">
            <el-option label="充值" value="充值" />
            <el-option label="收益" value="收益" />
            <el-option label="提现" value="提现" />
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-select v-model="searchForm.status" placeholder="请选择状态">
            <el-option label="正常" value="正常" />
            <el-option label="未审核" value="未审核" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="toSearch">查询</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!-- 表格 -->
    <div class="btn">
      <el-table stripe :data="tableData" style="width: 100%,height: 100%;">
        <el-table-column prop="id" label="编号" width="180" />
        <el-table-column
          prop="transferMoney"
          label="交易金额"
          width="180"
        />

        <el-table-column label="交易时间">
          <template slot-scope="scope">
            {{ moment(scope.row.transferTime).format("YYYY-MM-DD HH:mm:ss") }}
          </template>
        </el-table-column>

        <el-table-column prop="type" label="交易类型" />
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <!-- <el-tag v-if="scope.row.status==='正常'" type="success">{{scope.row.status}}</el-tag>
            <el-tag v-else type="danger">{{scope.row.status}}</el-tag> -->
            <!-- 使用三部运算符 -->
            <el-tag
              :type="scope.row.status === '正常' ? 'success' : 'danger'"
            >{{ scope.row.status }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="description" label="描述" />
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="page-div">
      <el-pagination
        :current-page="params.page"
        :page-sizes="[8, 10, 15, 20, 25, 30]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import { pageQuery, pageQuerySystemAccount } from '@/api/account'
import moment from 'moment'

export default {
  data() {
    return {
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      },

      systemData: [],
      // 表格展示的数据
      tableData: [],
      //  模糊搜索
      searchForm: {},
      total: 0,
      params: {
        page: 1,
        pageSize: 8
      }
    }
  },
  computed: {},
  watch: {
    params: {
      //  深度监听的分页参数
      handler() {
        this.queryData()
        this.querySystemData()
      },
      deep: true
    }
  },
  created() {
    this.querySystemData()
    this.queryData()
  },
  mounted() {},
  methods: {
    moment,
    // 获取顾客编号数据
    async querySystemData() {
      const res = await pageQuery({ page: 1, pageSize: 100 })
      this.customeData = res.data.list
    },
    // 查询
    toSearch() {
      // alert(1)
      this.queryData()
      this.querySystemData()
    },
    async queryData() {
      this.loading = true
      const temp = {
        ...this.params,
        ...this.searchForm
      }
      if (temp.Time) {
        temp.beginTime = temp.Time[0]
        temp.endTime = temp.Time[1]
        delete temp.Time
      }
      // 遍历对象
      for (const key in temp) {
        // 删除空值属性
        if (!temp[key]) {
          delete temp[key]
        }
      }
      // 分页模糊获取顾客账单数据
      const res = await pageQuerySystemAccount(temp)
      this.loading = false
      // console.log(res.data.list);
      this.tableData = res.data.list
      this.total = res.data.total
    },
    // 每页显示的条数发生变化时的事件处理程序
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      // this.params.pageSize = val;
      this.params = {
        page: 1,
        pageSize: val
      }
      // 发送数据请求
      // this.queryData();
    },
    // 当前页码发生变化时的事件处理程序
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.params.page = val
      // 发送数据请求
      // this.queryData();
    }
  }
}
</script>
<style lang="scss" scoped>
.search {
  display: flex;
  // height: 40px;
  .btn {
    // height: 100%;
    margin-right: 10px;
  }
}
.page-div {
  text-align: right;
  margin: 5px;
}
</style>
